home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C04 Speech / P04 Resource Speech / ResourceSpeech.c next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  2.9 KB  |  130 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    ResourceSpeech.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Speech.h>
  13.  
  14.  
  15. //____________________________________________________________
  16.  
  17. void     InitializeToolbox( void );
  18. Boolean  IsSpeechAvailable( void );
  19. void     OpenSpeechDialog( void );
  20. OSErr    SpeakOneString( Str255 );
  21.  
  22.  
  23. //____________________________________________________________
  24.  
  25. #define         rSpeechDialog          128
  26. #define         kSpeakShortButton        1
  27. #define         kSpeakLongButton         2
  28. #define         kQuitButton              3
  29. #define         rStringList            128
  30. #define         kShortStrIndex           1
  31. #define         kLongStrIndex            2
  32.  
  33.  
  34. //____________________________________________________________
  35.  
  36. void  main( void )
  37.    Boolean  speechPresent;
  38.  
  39.    InitializeToolbox();
  40.  
  41.    speechPresent = IsSpeechAvailable();
  42.    if ( speechPresent == false )
  43.       ExitToShell();
  44.  
  45.    OpenSpeechDialog();
  46. }
  47.  
  48.  
  49. //____________________________________________________________
  50.  
  51. void  OpenSpeechDialog( void )
  52. {
  53.    DialogPtr  theDialog;
  54.    short      theItem;
  55.    Boolean    allDone = false;
  56.    Str255     theString;
  57.    OSErr      theError;
  58.    
  59.    theDialog = GetNewDialog( rSpeechDialog, nil, (WindowPtr)-1L );
  60.    ShowWindow( theDialog );
  61.    SetPort( theDialog );
  62.    
  63.    while ( allDone == false )
  64.    {
  65.       ModalDialog( nil, &theItem );
  66.          
  67.       switch ( theItem )
  68.       {
  69.          case kSpeakShortButton:
  70.             GetIndString( theString, rStringList, kShortStrIndex ); 
  71.             theError = SpeakString( theString );
  72.             if ( theError != noErr )
  73.                ExitToShell();
  74.             break;
  75.  
  76.          case kSpeakLongButton:
  77.             GetIndString( theString, rStringList, kLongStrIndex ); 
  78.             theError = SpeakString( theString );
  79.             if ( theError != noErr )
  80.                ExitToShell();
  81.             break;
  82.  
  83.          case kQuitButton:
  84.             allDone = true;
  85.             break;
  86.       }
  87.    }
  88.    
  89.    DisposeDialog( theDialog ); 
  90. }
  91.  
  92.  
  93. //____________________________________________________________
  94.  
  95. Boolean  IsSpeechAvailable( void )
  96. {
  97.    OSErr    theError;
  98.    long     theResult;
  99.    Boolean  speechAvail;
  100.    
  101.    theError = Gestalt( gestaltSpeechAttr, &theResult );
  102.    if ( theError != noErr )
  103.       ExitToShell();
  104.       
  105.    speechAvail = theResult & ( 1 << gestaltSpeechMgrPresent );  
  106.    if ( speechAvail > 0 )
  107.       return ( true );
  108.    else
  109.       return ( false );
  110. }
  111.  
  112.  
  113. //____________________________________________________________
  114.  
  115. void  InitializeToolbox( void )
  116. {
  117.    InitGraf( &qd.thePort );
  118.    InitFonts();
  119.    InitWindows();
  120.    InitMenus();
  121.    TEInit();
  122.    InitDialogs( 0L );
  123.    FlushEvents( everyEvent, 0 );
  124.    InitCursor();
  125. }
  126.  
  127.  
  128.  
  129.